package com.basicorm;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;

public class EntityStorageImpl<T> implements EntityStorage<T> {
    private final EntityStorageImplEx<T> storage;

    public EntityStorageImpl(Connection connection, Class<T> classActual) {
        storage = new EntityStorageImplEx<T>(connection, classActual);
    }

    @Override
    public Collection<T> findByExample(T example) throws SQLException {
        try {
            return storage.findByExample(example);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (Throwable e) {
        	throw new RuntimeException(e);
		}
    }

    @Override
    public void insert(T entity) throws SQLException {
        try {
            storage.insert(entity);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Collection<T> findAll() throws SQLException {
        try {
            return storage.findAll();
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (SecurityException e) {
        	throw new RuntimeException(e);
		} catch (Throwable e) {
			throw new RuntimeException(e);
		}
    }
}
